package com.liuhuxiang.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.concurrent.TimeUnit;

/**
 * 启动类
 *
 * @author liuhuxiang
 * @version: ConfigApplication.java, 2023年03月02日 下午6:52 liuhuxiang  Exp $
 */
@SpringBootApplication
public class ConfigApplication {

    public static void main(String[] args) throws InterruptedException {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(ConfigApplication.class, args);


        //为了验证，实时推送最新值（如果在nacos配置文件中改动值），把这里改成死循环，看能否打印最新的值
       while(true){
           String userName = applicationContext.getEnvironment().getProperty("user.name");
           String age = applicationContext.getEnvironment().getProperty("user.age");
           String config = applicationContext.getEnvironment().getProperty("user.config");
           System.out.println("user name：" + userName + "   age：" + age+" config:"+config);
           TimeUnit.SECONDS.sleep(3);
       }

    }
}